﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Framework;
    using DotNetNuke.Services.Localization;
    using DotNetNuke.UI.UserControls;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class AdminProductDetail : UserControlBase
    {
        [AccessedThroughProperty("cmbCategory")]
        private DropDownList _cmbCategory;
        [AccessedThroughProperty("chkArchived")]
        private CheckBox _chkArchived;
        [AccessedThroughProperty("chkDeleted")]
        private CheckBox _chkDeleted;
        [AccessedThroughProperty("chkFeatured")]
        private CheckBox _chkFeatured;
        [AccessedThroughProperty("chkIsHidden")]
        private CheckBox _chkIsHidden;
        [AccessedThroughProperty("dlXMLData")]
        private DataList _dlXMLData;
        [AccessedThroughProperty("dshEditor")]
        private UserControl _dshEditor;
        [AccessedThroughProperty("labelArchived")]
        private UserControl _labelArchived;
        [AccessedThroughProperty("labelDeleted")]
        private UserControl _labelDeleted;
        [AccessedThroughProperty("labelDescription")]
        private UserControl _labelDescription;
        [AccessedThroughProperty("labelFeatured")]
        private UserControl _labelFeatured;
        [AccessedThroughProperty("labelManufacturer")]
        private UserControl _labelManufacturer;
        [AccessedThroughProperty("labelProductName")]
        private UserControl _labelProductName;
        [AccessedThroughProperty("labelProductRef")]
        private UserControl _labelProductRef;
        [AccessedThroughProperty("labelSEOName")]
        private UserControl _labelSEOName;
        [AccessedThroughProperty("labelSummary")]
        private UserControl _labelSummary;
        [AccessedThroughProperty("plIsHidden")]
        private UserControl _plIsHidden;
        [AccessedThroughProperty("plTagWords")]
        private UserControl _plTagWords;
        [AccessedThroughProperty("plTaxCategory")]
        private UserControl _plTaxCategory;
        private int _PortalID;
        [AccessedThroughProperty("ShowSelectLang")]
        private NEvoWeb.Modules.NB_Store.ShowSelectLang _ShowSelectLang;
        [AccessedThroughProperty("ShowSelectLang1")]
        private NEvoWeb.Modules.NB_Store.ShowSelectLang _ShowSelectLang1;
        [AccessedThroughProperty("ShowSelectLang2")]
        private NEvoWeb.Modules.NB_Store.ShowSelectLang _ShowSelectLang2;
        [AccessedThroughProperty("ShowSelectLang3")]
        private NEvoWeb.Modules.NB_Store.ShowSelectLang _ShowSelectLang3;
        [AccessedThroughProperty("ShowSelectLang4")]
        private NEvoWeb.Modules.NB_Store.ShowSelectLang _ShowSelectLang4;
        [AccessedThroughProperty("ShowSelectLang5")]
        private NEvoWeb.Modules.NB_Store.ShowSelectLang _ShowSelectLang5;
        [AccessedThroughProperty("tblDescription")]
        private HtmlTable _tblDescription;
        [AccessedThroughProperty("txtDescription")]
        private UserControl _txtDescription;
        [AccessedThroughProperty("txtManufacturer")]
        private TextBox _txtManufacturer;
        [AccessedThroughProperty("txtProductName")]
        private TextBox _txtProductName;
        [AccessedThroughProperty("txtProductRef")]
        private TextBox _txtProductRef;
        [AccessedThroughProperty("txtSEOName")]
        private TextBox _txtSEOName;
        [AccessedThroughProperty("txtSummary")]
        private TextBox _txtSummary;
        [AccessedThroughProperty("txtTagWords")]
        private TextBox _txtTagWords;
        private string ResourceFile;

        public event HideUpdateEventHandler HideUpdate;

        public AdminProductDetail()
        {
            base.Load += new EventHandler(this.Page_Load);
            base.Init += new EventHandler(this.Page_Init);
            base.PreRender += new EventHandler(this.Page_PreRender);
        }

        private void Page_Init(object sender, EventArgs e)
        {
            NB_Store_SettingsTextInfo info = new SettingsController().GetSettingsText(((BaseAdminModule) this.Parent.Parent.Parent).PortalId, "productxmldata.template", SharedFunctions.GetCurrentCulture());
            if (info != null)
            {
                if (info.SettingText != "")
                {
                    this.dlXMLData.ItemTemplate = new GenXMLTemplate(this.Server.HtmlDecode(info.SettingText));
                }
                else
                {
                    this.dlXMLData.Visible = false;
                }
            }
            else
            {
                this.dlXMLData.Visible = false;
            }
        }

        private void Page_Load(object sender, EventArgs e)
        {
            this.ResourceFile = DotNetNuke.Services.Localization.Localization.GetResourceFile(this, this.GetType().BaseType.Name + ".ascx");
            int num = -1;
            if ((this.Request.QueryString["ProdID"] != null) && Versioned.IsNumeric(this.Request.QueryString["ProdID"]))
            {
                num = Conversions.ToInteger(this.Request.QueryString["ProdID"]);
            }
        }

        private void Page_PreRender(object sender, EventArgs e)
        {
            this.ShowSelectLang.Refresh();
            this.ShowSelectLang1.Refresh();
            this.ShowSelectLang2.Refresh();
            this.ShowSelectLang3.Refresh();
            this.ShowSelectLang5.Refresh();
            this.ShowSelectLang4.Refresh();
        }

        public void populateDetails(NB_Store_ProductsInfo objInfo)
        {
            if (objInfo != null)
            {
                SharedFunctions.populateCategoryList(this.PortalSettings.PortalId, this.cmbCategory, "-1", " ", objInfo.TaxCategoryID.ToString());
                ((TextEditor) this.txtDescription).Text = objInfo.Description;
                this.txtManufacturer.Text = objInfo.Manufacturer;
                this.txtSummary.Text = objInfo.Summary;
                this.txtProductName.Text = objInfo.ProductName;
                this.txtSEOName.Text = objInfo.SEOName;
                this.txtProductRef.Text = objInfo.ProductRef;
                this.chkArchived.Checked = objInfo.Archived;
                this.chkFeatured.Checked = objInfo.Featured;
                this.chkDeleted.Checked = objInfo.IsDeleted;
                this.chkIsHidden.Checked = objInfo.IsHidden;
                this.txtTagWords.Text = objInfo.TagWords;
                if (this.dlXMLData.Visible)
                {
                    SharedFunctions.DisplayXMLData(objInfo, this.dlXMLData);
                }
            }
            else
            {
                SharedFunctions.populateCategoryList(this.PortalSettings.PortalId, this.cmbCategory);
            }
        }

        public NB_Store_ProductsInfo UpdateDetails(string Lang, int UsrId, int ProdID)
        {
            ProductController controller = new ProductController();
            NB_Store_ProductsInfo objInfo = new NB_Store_ProductsInfo();
            if (ProdID > 0)
            {
                objInfo = controller.GetProduct(ProdID, Lang);
            }
            if (objInfo == null)
            {
                objInfo = new NB_Store_ProductsInfo();
            }
            objInfo.Archived = this.chkArchived.Checked;
            if (Versioned.IsNumeric(this.cmbCategory.SelectedValue))
            {
                objInfo.TaxCategoryID = Conversions.ToInteger(this.cmbCategory.SelectedValue);
            }
            else
            {
                objInfo.TaxCategoryID = -1;
            }
            objInfo.CreatedByUser = Conversions.ToString(UsrId);
            if (DateTime.Compare(objInfo.CreatedDate, Null.NullDate) == 0)
            {
                objInfo.CreatedDate = DateAndTime.Now;
            }
            objInfo.Description = ((TextEditor) this.txtDescription).Text;
            objInfo.Featured = this.chkFeatured.Checked;
            objInfo.IsDeleted = this.chkDeleted.Checked;
            objInfo.IsHidden = this.chkIsHidden.Checked;
            objInfo.Lang = Lang;
            objInfo.Manufacturer = this.txtManufacturer.Text;
            objInfo.PortalID = this.PortalSettings.PortalId;
            objInfo.ProductID = ProdID;
            objInfo.Summary = this.txtSummary.Text;
            objInfo.ProductName = this.txtProductName.Text;
            objInfo.SEOName = this.txtSEOName.Text;
            objInfo.ProductRef = this.txtProductRef.Text;
            if (this.dlXMLData.Visible)
            {
                objInfo.XMLData = SharedFunctions.getGenXML(this.dlXMLData, 0, "en-GB");
            }
            else
            {
                objInfo.XMLData = "";
            }
            objInfo.TagWords = this.txtTagWords.Text;
            return controller.UpdateObjProduct(objInfo);
        }

        protected virtual DropDownList cmbCategory
        {
            get
            {
                return this._cmbCategory;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._cmbCategory = value;
            }
        }

        protected virtual CheckBox chkArchived
        {
            get
            {
                return this._chkArchived;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._chkArchived = value;
            }
        }

        protected virtual CheckBox chkDeleted
        {
            get
            {
                return this._chkDeleted;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._chkDeleted = value;
            }
        }

        protected virtual CheckBox chkFeatured
        {
            get
            {
                return this._chkFeatured;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._chkFeatured = value;
            }
        }

        protected virtual CheckBox chkIsHidden
        {
            get
            {
                return this._chkIsHidden;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._chkIsHidden = value;
            }
        }

        protected virtual DataList dlXMLData
        {
            get
            {
                return this._dlXMLData;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._dlXMLData = value;
            }
        }

        protected virtual UserControl dshEditor
        {
            get
            {
                return this._dshEditor;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._dshEditor = value;
            }
        }

        protected virtual UserControl labelArchived
        {
            get
            {
                return this._labelArchived;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._labelArchived = value;
            }
        }

        protected virtual UserControl labelDeleted
        {
            get
            {
                return this._labelDeleted;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._labelDeleted = value;
            }
        }

        protected virtual UserControl labelDescription
        {
            get
            {
                return this._labelDescription;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._labelDescription = value;
            }
        }

        protected virtual UserControl labelFeatured
        {
            get
            {
                return this._labelFeatured;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._labelFeatured = value;
            }
        }

        protected virtual UserControl labelManufacturer
        {
            get
            {
                return this._labelManufacturer;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._labelManufacturer = value;
            }
        }

        protected virtual UserControl labelProductName
        {
            get
            {
                return this._labelProductName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._labelProductName = value;
            }
        }

        protected virtual UserControl labelProductRef
        {
            get
            {
                return this._labelProductRef;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._labelProductRef = value;
            }
        }

        protected virtual UserControl labelSEOName
        {
            get
            {
                return this._labelSEOName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._labelSEOName = value;
            }
        }

        protected virtual UserControl labelSummary
        {
            get
            {
                return this._labelSummary;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._labelSummary = value;
            }
        }

        protected virtual UserControl plIsHidden
        {
            get
            {
                return this._plIsHidden;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._plIsHidden = value;
            }
        }

        protected virtual UserControl plTagWords
        {
            get
            {
                return this._plTagWords;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._plTagWords = value;
            }
        }

        protected virtual UserControl plTaxCategory
        {
            get
            {
                return this._plTaxCategory;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._plTaxCategory = value;
            }
        }

        protected virtual NEvoWeb.Modules.NB_Store.ShowSelectLang ShowSelectLang
        {
            get
            {
                return this._ShowSelectLang;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._ShowSelectLang = value;
            }
        }

        protected virtual NEvoWeb.Modules.NB_Store.ShowSelectLang ShowSelectLang1
        {
            get
            {
                return this._ShowSelectLang1;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._ShowSelectLang1 = value;
            }
        }

        protected virtual NEvoWeb.Modules.NB_Store.ShowSelectLang ShowSelectLang2
        {
            get
            {
                return this._ShowSelectLang2;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._ShowSelectLang2 = value;
            }
        }

        protected virtual NEvoWeb.Modules.NB_Store.ShowSelectLang ShowSelectLang3
        {
            get
            {
                return this._ShowSelectLang3;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._ShowSelectLang3 = value;
            }
        }

        protected virtual NEvoWeb.Modules.NB_Store.ShowSelectLang ShowSelectLang4
        {
            get
            {
                return this._ShowSelectLang4;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._ShowSelectLang4 = value;
            }
        }

        protected virtual NEvoWeb.Modules.NB_Store.ShowSelectLang ShowSelectLang5
        {
            get
            {
                return this._ShowSelectLang5;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._ShowSelectLang5 = value;
            }
        }

        protected virtual HtmlTable tblDescription
        {
            get
            {
                return this._tblDescription;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._tblDescription = value;
            }
        }

        protected virtual UserControl txtDescription
        {
            get
            {
                return this._txtDescription;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._txtDescription = value;
            }
        }

        protected virtual TextBox txtManufacturer
        {
            get
            {
                return this._txtManufacturer;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._txtManufacturer = value;
            }
        }

        protected virtual TextBox txtProductName
        {
            get
            {
                return this._txtProductName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._txtProductName = value;
            }
        }

        protected virtual TextBox txtProductRef
        {
            get
            {
                return this._txtProductRef;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._txtProductRef = value;
            }
        }

        protected virtual TextBox txtSEOName
        {
            get
            {
                return this._txtSEOName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._txtSEOName = value;
            }
        }

        protected virtual TextBox txtSummary
        {
            get
            {
                return this._txtSummary;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._txtSummary = value;
            }
        }

        protected virtual TextBox txtTagWords
        {
            get
            {
                return this._txtTagWords;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._txtTagWords = value;
            }
        }

        public delegate void HideUpdateEventHandler();
    }
}

